package com.example.util;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;

import com.example.admin.entity.SysUser;
import com.example.common.entity.CommonUser;

/**
 * 获取当前登陆对象
 * 
 * @author wangkai
 *
 * @date: 2019年6月3日 下午2:56:48
 */
public class CurrentUser {

	/**
	 * 返回Subject
	 * @return
	 */
	public static Subject getSubject() {
		return SecurityUtils.getSubject();
	}
	
	/**
	 * 返回session
	 * @return
	 */
	public static Session getSession(){
		return getSubject().getSession();
	}

	/**
	 * 当前系统用户
	 * 
	 * @return
	 */
	public static SysUser getAdminUser() {
		SysUser user = (SysUser) getSubject().getPrincipal();
		return user;
	}
	
	/**
	 * 当前普通用户
	 * @return
	 */
	public static CommonUser getCommonUser() {
		CommonUser user = (CommonUser) getSubject().getPrincipal();
		return user;
	}
	
	

	/**
	 * 退出当前账号
	 */
	public static void logout() {
		
		getSubject().logout();
	}

}
